import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from "@/views/Index.vue";
import Books from "@/components/admin/Books.vue";
import Borrow from "@/components/admin/Borrow.vue";
import Cards from "@/components/admin/Cards.vue";
import Users from "@/components/admin/Users.vue";
import Login from "@/views/Login.vue";



Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    name: '首页',
    component: Index,
      children:[
          {
              path: '/books',
              name: '图书管理',
              component: Books
          }, {
              path: '/users',
              name: '读者管理',
              component: Users
          }, {
              path: '/cards',
              name: '借阅卡管理',
              component: Cards
          }, {
              path: '/borrows',
              name: '借阅管理',
              component: Borrow
          },
          {
              path: "/login",
              name: "登录",
              component: Login
          },
      ]
  },


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
// this.$router.beforeEach(to => {
//      if(to.path=='/login'){
//          next();
//      }else{
//          if(window.sessionStorage.getItem("card")==null){
//              this.$message.error("对不起，请登录");
//              this.$router.push("/login");
//          }
//      }
// })
